using System;
using System.Collections.Generic;
using System.Text;
using QLHXNK.DataAccess;
using System.Data;

namespace QLHXNK.BusinessLogic
{
    class Expenses
    {
        private int expensesID;
        private String expensesCode;
        private String expensesName;
        private String remark;

        #region Properties
        public int ID
        {
            get { return expensesID; }
        }
        public String Code
        {
            get { return expensesCode; }
            set { expensesCode = value; }
        }
        public String Name
        {
            get { return expensesName; }
            set { expensesName = value; }
        }

        public String Remark
        {
            get { return remark; }
            set { remark = value; }
        }

        

        #endregion
        public Expenses(int expensesID, String expensesCode, String expensesName, String remark)
        {
            this.expensesID = expensesID;
            this.expensesCode = expensesCode;
            this.expensesName = expensesName;
            this.remark = remark;
        }

        #region ----------------------------------------Lấy thông tin chi phí----------------------------------------

        public static DataTable ListExpenses()
        {
            try
            {
                return ExspencesData.GetExpenses("",-1);
            }
            catch 
            {
                return null;
            }
        }

        public static DataTable GetExpensesByCode(String expensesCode)
        {
            try
            {
                return ExspencesData.GetExpenses(expensesCode,-1);
            }
            catch
            {
                return null;
            }
        }
        public static DataTable GetExpensesByID(int ID)
        {
            try
            {
                return ExspencesData.GetExpenses("",ID);
            }
            catch
            {
                return null;
            }
        }

        public static DataTable GetExpensesInMonthlyExpenses(int ID)
        {
            try
            {
                return ExspencesData.GetExpensesInMonthlyExpenses(ID);
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region ------------------------------------------Thêm, xoá, sửa-------------------------------------------

        public static Expenses CreateExspences(String expensesCode, String expensesName, String remark)
        {
            try
            {
                int id = ExspencesData.CreateExspences(expensesCode, expensesName, remark);
                Expenses expenses = null;
                if (id != 0)
                    expenses = new Expenses(id, expensesCode, expensesName,remark);
                return expenses;
            }
            catch 
            {
                return null;
            }
        }

        public int DeleteExpenses()
        {
            try
            {
                return ExspencesData.DeleteExpenses(this.expensesID);
            }
            catch 
            {
                return 0;
            }
        }

        public int Save()
        {
            try
            {
                return ExspencesData.UpdateExpenses(this.expensesID, this.expensesCode, this.expensesName, this.remark);
            }
            catch 
            {
                return 0;
            }
        }

        public int UpdateExpenses(String expensesCode, String expensesName, String remark)
        {
            try
            {
                this.expensesCode = expensesCode;
                this.expensesName = expensesName;
                this.remark = remark;
                return Save();
            }
            catch 
            {
                return 0;
            }
        }
    #endregion
    }
}
